package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.web.controller.tool.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JingfeiDeptMonth;
import com.ruoyi.system.service.IJingfeiDeptMonthService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * jingfeideptyueController
 * 
 * @author ruoyi
 * @date 2024-07-11
 */
@Controller
@RequestMapping("/system/jingfeideptmonth")
public class JingfeiDeptMonthController extends BaseController
{
    private String prefix = "system/jingfeideptmonth";

    @Autowired
    private IJingfeiDeptMonthService jingfeiDeptMonthService;

    @RequiresPermissions("system:jingfeideptmonth:view")
    @GetMapping()
    public String month()
    {
        return prefix + "/month";
    }

    /**
     * 查询jingfeideptyue列表
     */
    @RequiresPermissions("system:jingfeideptmonth:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JingfeiDeptMonth jingfeiDeptMonth)
    {
        startPage();
        List<JingfeiDeptMonth> list = jingfeiDeptMonthService.selectJingfeiDeptMonthList(jingfeiDeptMonth);
        return getDataTable(list);
    }

    /**
     * 导出jingfeideptyue列表
     */
    @RequiresPermissions("system:jingfeideptmonth:export")
    @Log(title = "jingfeideptyue", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JingfeiDeptMonth jingfeiDeptMonth)
    {
        List<JingfeiDeptMonth> list = jingfeiDeptMonthService.selectJingfeiDeptMonthList(jingfeiDeptMonth);
        ExcelUtil<JingfeiDeptMonth> util = new ExcelUtil<JingfeiDeptMonth>(JingfeiDeptMonth.class);
        return util.exportExcel(list, "jingfeideptyue数据");
    }

    /**
     * 新增jingfeideptyue
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存jingfeideptyue
     */
    @RequiresPermissions("system:jingfeideptmonth:add")
    @Log(title = "jingfeideptyue", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JingfeiDeptMonth jingfeiDeptMonth)
    {
        return toAjax(jingfeiDeptMonthService.insertJingfeiDeptMonth(jingfeiDeptMonth));
    }

    /**
     * 修改jingfeideptyue
     */
    @RequiresPermissions("system:jingfeideptmonth:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JingfeiDeptMonth jingfeiDeptMonth = jingfeiDeptMonthService.selectJingfeiDeptMonthById(id);
        mmap.put("jingfeiDeptMonth", jingfeiDeptMonth);
        return prefix + "/edit";
    }

    /**
     * 修改保存jingfeideptyue
     */
    @RequiresPermissions("system:jingfeideptmonth:edit")
    @Log(title = "jingfeideptyue", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JingfeiDeptMonth jingfeiDeptMonth)
    {
        return toAjax(jingfeiDeptMonthService.updateJingfeiDeptMonth(jingfeiDeptMonth));
    }

    /**
     * 删除jingfeideptyue
     */
    @RequiresPermissions("system:jingfeideptmonth:remove")
    @Log(title = "jingfeideptyue", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jingfeiDeptMonthService.deleteJingfeiDeptMonthByIds(ids));
    }


    @Log(title = "单位经费发放列表", businessType = BusinessType.UPDATE)
    @PostMapping("/findmonthlist")
    @ResponseBody
    public JsonResult findmonthlist(@RequestParam("piciid")String pppiciid,@RequestParam("deptid")String ppdeptid, HttpServletRequest request) {

        try {
            HttpSession session = request.getSession();
            JingfeiDeptMonth mm查询条件 = new JingfeiDeptMonth();
            mm查询条件.setDeptid(ppdeptid);
            mm查询条件.setJingfeipiciid(pppiciid);
            return JsonResult.getSuccessResult(jingfeiDeptMonthService.selectJingfeiDeptMonthList(mm查询条件));
        } catch (Exception e) {
            logger.error("jingfeideptmonth -> findmonthlist: "+e.getMessage());
            return JsonResult.getErrorResult("经费月份批次列表查询失败");
        }
    }

    @Log(title = "单位经费发放列表", businessType = BusinessType.UPDATE)
    @PostMapping("/findnotusedmonth")
    @ResponseBody
    public JsonResult findnotusedmonth(@RequestParam("deptid")String ppdeptid, HttpServletRequest request) {

        try {
            HttpSession session = request.getSession();
            JingfeiDeptMonth mm查询条件 = new JingfeiDeptMonth();
            mm查询条件.setDeptid(ppdeptid);
            mm查询条件.setIsuse(0l);
            mm查询条件.setIsqueren(1l);
            return JsonResult.getSuccessResult(jingfeiDeptMonthService.selectJingfeiDeptMonthList(mm查询条件));
        } catch (Exception e) {
            logger.error("jingfeideptmonth -> findnotusedmonth: "+e.getMessage());
            return JsonResult.getErrorResult("可用经费月份批次列表查询失败");
        }
    }

}
